import store from "@/store"

/**
 * 公共权限方法
 * @param {Array} value
 * @returns {Boolean}
 */
export default {
  install(Vue) {
    Vue.prototype.checkPermission = (value) => {
      if (value && value instanceof Array && value.length > 0) {
		  console.log(store.state.vuex_user.roles)
        const roles = store.state.vuex_user.roles;
        const permissionRoles = value
        return roles.some(role => {
          return permissionRoles.includes(role.roleKey)
        })
      } else {
        console.error(`配置错误，参考示例:v-if="checkPermission(['manager','admin','sample_admin','approver','chairman'])"`)
        return false
      }
    }
  }
}

// ASSISTANT("文员","assistant"),
// INSPECTOR("检验员","inspector"),
// MAININSPECTOR("主检","mainInspector"),
// APPROVER("审批人","approver"),
// ORG_ADMIN("机构管理员","orgAdmin"),
// SAMPLE_ADMIN("样品管理员","sample_admin"),
// CHAIRMAN("室主任","chairman"),
// CENTER_LEADER("中心领导","centerLeader"),
// OFFICER("办公室人员","officer")